package com.heima.health.controller;

import com.heima.health.dto.CheckGroupDto;
import com.heima.health.entity.QueryPageBean;
import com.heima.health.entity.Result;
import com.heima.health.pojo.CheckGroup;
import com.heima.health.service.CheckGroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("checkgroup")
@Api(tags = "检查组管理开发")
public class CheckGroupController {

    @Reference
    private CheckGroupService checkGroupService;

    @PostMapping("findPage")
    @ApiOperation(value = "分页查询",notes = "分页查询所有检查组列表信息")
    public Result findPage(@RequestBody QueryPageBean queryPageBean){
        return new Result(checkGroupService.findPage(queryPageBean));
    }

    @PostMapping("saveOrUpdate")
    @ApiOperation(value = "新增或更新检查组",notes = "未携带id时新增，携带id时更新检查组")
    public Result saveOrUpdate(@RequestBody CheckGroupDto checkGroupDto){
        return new Result(checkGroupService.saveUpdate(checkGroupDto));
    }

    @GetMapping("findCidByGid/{gid}")
    @ApiOperation(value = "根据组id查询检查项id",notes = "根据传过来的id查询检查项ids")
    public Result findCidByGid(@PathVariable Integer gid){
        return new Result(checkGroupService.findByGid(gid));
    }

    @DeleteMapping("deleteById/{id}")
    @ApiOperation(value = "逻辑删除",notes = "根据id删除检查组")
    public Result deleteById(@PathVariable("id") Integer id){
        CheckGroup checkGroup=new CheckGroup();
        checkGroup.setId(id);
        checkGroup.setIs_delete(1);
        return new Result(checkGroupService.updateById(checkGroup));
    }

    @GetMapping("findAll")
    @ApiOperation(value = "查询所有",notes = "查询所有检查项列表信息")
    public Result findAll(){
        return new Result(checkGroupService.list());
    }
}
